%define commit 95e327e134bcda9ff5eca85bae55783c6ed33664
%define commit_short %(echo %{commit} | head -c6)

Summary(ru_RU.UTF-8):	Авторизация в ОС через учетную запись mos.ru
Summary:	Authentication via mos.ru identity
Name:		mos-auth
Version:	3.14
Release:	5.git%{commit_short}.3
# TODO: update/change license
License:	Proprietary
Group:		Graphical desktop/Other
Url:		https://hub.mos.ru/mos/src/mos-auth
Vendor:		MOS
Source0:	https://hub.mos.ru/mos/src/mos-auth/-/archive/%{commit}/%{name}-%{commit}.tar.gz
BuildRequires:	cmake
BuildRequires:	kf5plasma-devel
# for %%check
BuildRequires:	py-ini-config
# for converting man-pages
BuildRequires:	/usr/bin/rst2man

%description
Authentication via mos.ru identity

%description -l ru_RU.UTF-8
Авторизация в ОС через учетную запись mos.ru

#------------------------------------------------------------------

%package core
Summary(ru_RU.UTF-8): Настройки и плагин авторизации через mos.ru для plasma и sddm
Summary:	Authentication via mos.ru plugin and settings for plasma and sddm
Requires:	pam
Requires:	py-ini-config >= 2
Requires:	polkit-sddm-nm
Requires:	sudo
Requires:	plasma5-nm
Requires:	%{_libdir}/qt5/qml/org/mos
Recommends:	%{name}-roles
Recommends:	bash-completion
# prefer over mos-std-panel
Suggests:	mos-std-desktop
Conflicts:	mos-auth < 3.2
Obsoletes:	mos-auth < 3.2

%description core
Authentication via mos.ru plugin and settings for plasma and sddm

%description -l ru_RU.UTF-8 core
Реализация авторизации с использованием учётных записей school.mos.ru.
Пакет содержит плагин для plasma и sddm, а так же настройки системы.

%files core
%dir %{_var}/lib/mos-auth
%dir %{_sysconfdir}/mos-auth
%dir %{_sysconfdir}/mos-auth/mos-auth.conf.d

%{_bindir}/mos-auth-config
%{_bindir}/prepare-guest-account

%{_kde5_qmldir}/org/mos/auth

%{_datadir}/mos-auth
%{_datadir}/sddm/themes/mos-auth
%{_datadir}/bash-completion/completions/mos-auth-config

%config(noreplace) %{_sysconfdir}/mos-auth/mos-auth.conf
%{_sysconfdir}/sudoers.d/sudo-sddm-privileges
%{_sysconfdir}/security/limits.d/40-guest-limitations.conf

%{_mandir}/man5/mos-auth.conf.5.*
%{_mandir}/ru/man5/mos-auth.conf.5.*
%{_mandir}/man8/mos-auth-config.8.*
%{_mandir}/ru/man8/mos-auth-config.8.*

%post core
if test -f /var/lib/mos-auth/enabled
then
	mos-auth-config disable
	mos-auth-config enable
fi

%preun core
# удаление, не обновление
if [ $1 -eq 0 ]
then
	mos-auth-config disable
fi

#-----------------------------------------------------------------------------------

%package folders
Summary(ru_RU.UTF-8): Сетевые папки для пользователей school.mos.ru
Summary:	Shared folders school.mos.ru
Requires:	%{name}-core
Requires:	glusterfs-client
Requires:	glusterfs-fuse
Requires:	glusterfs-extra-xlators
BuildArch:	noarch

%description folders
Shared folders school.mos.ru

%description -l ru_RU.UTF-8 folders
Подключение сетевых папок для переноса файлов внутри школы
для пользователей авторизованных через school.mos.ru

%files folders
%{_bindir}/mos-auth-folders-functions
%{_bindir}/mount-shared-folder-on-login
%{_prefix}/lib/NetworkManager/dispatcher.d/40-mount-shared-folder

#------------------------------------------------------------------

%package dbus-conf
Summary(ru_RU.UTF-8): Конфигурация для шины DBus
Summary:	DBus configuration
Requires:	%{name}-core >= 3.12
Recommends:	/usr/bin/qdbus
BuildArch:	noarch

%description dbus-conf
Added the ability to log into the SDDM theme using the DBus bus.

Example: qdbus --system org.mos.auth / login user 123

For guest (empty password): qdbus --system org.mos.auth / login guest

The command is executed from a user with root rights.

%description -l ru_RU.UTF-8 dbus-conf
Добавлена возможность входа в тему SDDM с помощью шины DBus.

Пример команды: qdbus --system org.mos.auth / login user 123

Для гостя (с пустым паролем): qdbus --system org.mos.auth / login guest

Команда выполняется от пользователя с правами root.

%files dbus-conf
%{_datadir}/dbus-1/system.d/org.mos.auth.conf

#------------------------------------------------------------------

%package roles
Summary(ru_RU.UTF-8):	Конфигурация ролей связанных со стандартными из авторизации mos.ru
Summary:	Configuration of roles associated with standard authorization mos.ru
Group:		System/Configuration/Other
Requires:	%{name}-core >= 3.12
Requires:	libnss-role
Requires:	cups
BuildArch:	noarch

%description roles
Linking standard roles related to authorization mos.ru with system groups.
The mos-teacher group has a rule of presence in the lpadmin group for printer management.

%description -l ru_RU.UTF-8 roles
Связь стандартных ролей связанных с авторизацией mos.ru с системными группами.
Для группы mos-teacher установлено правило присутствия в группе lpadmin для управления принтером.

%files roles
%config(noreplace) %{_sysconfdir}/role.d/mos-cups.role

#------------------------------------------------------------------

%prep
%autosetup -p1 -n %{name}-%{commit}

%build
# Convert man-pages from rst
cd mos-auth-config/man
rst2man mos-auth.conf.5.rst mos-auth.conf.5
rst2man mos-auth.conf.5.ru.rst mos-auth.conf.5.ru
rst2man mos-auth-config.8.rst mos-auth-config.8
rst2man mos-auth-config.8.ru.rst mos-auth-config.8.ru

cd ../../service-qml-plugin
%cmake -DCMAKE_INSTALL_PREFIX=%{_qt5_prefix}/
%make

%install
%make_install -C service-qml-plugin/build

mkdir -p %{buildroot}%{_var}/lib/mos-auth
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_datadir}/dbus-1/system.d
mkdir -p %{buildroot}%{_datadir}/mos-auth
mkdir -p %{buildroot}%{_datadir}/sddm/themes/mos-auth
mkdir -p %{buildroot}%{_datadir}/bash-completion/completions
mkdir -p %{buildroot}%{_prefix}/lib/NetworkManager/dispatcher.d
mkdir -p %{buildroot}%{_sysconfdir}/sudoers.d
mkdir -p %{buildroot}%{_sysconfdir}/mos-auth
mkdir -p %{buildroot}%{_sysconfdir}/mos-auth/mos-auth.conf.d
mkdir -p %{buildroot}%{_sysconfdir}/security/limits.d
mkdir -p %{buildroot}%{_sysconfdir}/role.d
mkdir -p %{buildroot}%{_mandir}/man5
mkdir -p %{buildroot}%{_mandir}/ru/man5
mkdir -p %{buildroot}%{_mandir}/man8
mkdir -p %{buildroot}%{_mandir}/ru/man8

install -m755 mos-auth-config/mos-auth-config.sh %{buildroot}%{_bindir}/mos-auth-config
cp -rv ./sddm-theme/*  %{buildroot}%{_datadir}/sddm/themes/mos-auth/
install -m644 service-qml-plugin/sudo-sddm-privileges %{buildroot}%{_sysconfdir}/sudoers.d/
install -m644 service-qml-plugin/dbus-rules/org.mos.auth.conf %{buildroot}%{_datadir}/dbus-1/system.d
install -m644 mos-auth-config/bash-completion/mos-auth-config %{buildroot}%{_datadir}/bash-completion/completions/
install -m644 mos-auth-config/mos-auth.conf %{buildroot}%{_sysconfdir}/mos-auth/

install -m644 mos-auth-config/man/mos-auth.conf.5 %{buildroot}%{_mandir}/man5/
install -m644 mos-auth-config/man/mos-auth.conf.5.ru %{buildroot}%{_mandir}/ru/man5/mos-auth.conf.5
install -m644 mos-auth-config/man/mos-auth-config.8 %{buildroot}%{_mandir}/man8/
install -m644 mos-auth-config/man/mos-auth-config.8.ru %{buildroot}%{_mandir}/ru/man8/mos-auth-config.8

install -m755 prepare-guest-account/prepare-guest-account.sh %{buildroot}%{_bindir}/prepare-guest-account
install -m644 prepare-guest-account/40-guest-limitations.conf %{buildroot}%{_sysconfdir}/security/limits.d

install -m755 mos-auth-folders/mos-auth-folders-functions.sh %{buildroot}%{_bindir}/mos-auth-folders-functions
install -m755 mos-auth-folders/mount-shared-folder-on-login.sh %{buildroot}%{_bindir}/mount-shared-folder-on-login
install -m755 mos-auth-folders/mount-shared-folder.sh %{buildroot}%{_prefix}/lib/NetworkManager/dispatcher.d/40-mount-shared-folder
echo "mos-teacher:lpadmin" > %{buildroot}%{_sysconfdir}/role.d/mos-cups.role

%check
cd mos-auth-config
./test.sh
